package com.yzt.dynamicmodule.utils

import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.interfaces.OnQueryFilterListener
import java.util.*

/**video/mp4
 * @Desc 图片大小过滤
 * @Author macjay
 * @Time 2022/12/30 17:24
 */
class DynamicQueryFilterListener(dynamicImageSize: Long, dynamicVideoSize: Long) :
    OnQueryFilterListener {

    private val imageSize = dynamicImageSize * 1024 * 1024
    private val videoSize = dynamicVideoSize * 1024 * 1024

    override fun onFilter(media: LocalMedia): Boolean {
        if (media.fileName.lowercase(Locale.getDefault()).endsWith("mp4")
            || media.fileName.lowercase(Locale.getDefault()).endsWith("MP4")
        ) {
            return media.size >= videoSize
        } else {
            return media.size >= imageSize
        }
    }
}